package school30.io.memory;

import school30.io.*;

public class MemoryFileReader extends FileReader{
    private MemoryFileStorage storage;
    private File path;
    private byte[] buf;
    private int n;

    public MemoryFileReader(MemoryFileStorage st, File path)
    {
        this.storage = st;
        this.path = path;
        this.buf = st.readFile(path);;
        n = 0;
    }

    public long read(byte[] b, long numbytes) {
        int br = 0;
        for (int i = 0; i < numbytes; i++)
        {
            if (n >= buf.length)
                return br;
            b[i] = buf[n];
            n++;
            br++;
        }
        return br;
    }

    public long size() {
        return buf.length;
    }

    public void close() {
    }
}
